import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/api/home.dart';
import 'package:flutter_enjoy_plus/pages/home/components/home_list.dart';
import 'package:flutter_enjoy_plus/pages/home/components/home_nav.dart';
import 'package:flutter_enjoy_plus/utils/toast.dart';
import 'package:flutter_enjoy_plus/utils/tokenManager.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<HomePage> {
  List AnnounceList = [];
  int _count_down = 60;
  Timer? timer;
  @override
  void initState() {
    super.initState();
    getAnnounceList();
  }
  getAnnounceList() async {
    final res = await getAnnounceListApi();
    setState(() {
      AnnounceList = res;
    });
    PromptAction.showSuccessToast('获取公告成功');
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromRGBO(229, 231, 241, 1),
      appBar: AppBar(
        title: const Text('享+社区'),
        centerTitle: true,
        backgroundColor: Colors.transparent,
      ),
      body: ListView(
        padding: const EdgeInsets.all(10),
        children: [
          const SizedBox(width: 10),
          // Expanded(
          //   child: ElevatedButton(
          //     onPressed: (){
          //       tokenManager.setToken('2222');
          //       PromptAction.showToast('存储成功');
          //     },
          //     child: const Text('存储token'),
          //   )
          //   ),
          //             const SizedBox(width: 10),
          // Expanded(
          //   child: ElevatedButton(
          //     onPressed: (){
          //       timer = Timer.periodic(Duration(seconds: 1), (timer){
          //         _count_down--;
          //         setState(() {});
          //       });
          //     },
          //     child: const Text('开始倒计时'),
          //   )
          //   ),
          // const SizedBox(width: 10),
          // Text('$_count_down'),
          // Expanded(
          //   child: ElevatedButton(
          //     onPressed: (){
          //       timer?.cancel();
          //     },
          //     child: const Text('关定时器'),
          //   )
          //   ),
          //             const SizedBox(width: 10),
          // Expanded(
          //   child: ElevatedButton(
          //     onPressed: (){
          //       Future.delayed(const Duration(seconds: 3),(){
          //         PromptAction.showToast('延时器');
          //       });
          //     },
          //     child: const Text('延时器'),
          //   )
          //   ),

          // 导航条
          const HomeNav(),
          // 图片
          ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: Image.asset('assets/images/banner@2x.jpg')
          ),
          // 社区公告
          HomeList(AnnounceList:AnnounceList)
        ]
      )
    );
  }
}
